#include "KdBuildQueue.h"
#include "AABB.h"

//QueueEntry::QueueEntry(KdNode* n, Triangle** tl, const int nt, const AABB& a) :
//	node(n), triangleList(tl), numTriangles(nt), aabb(a)
//{
//}

KdBuildQueue::KdBuildQueue() :
	head(0), tail(0), counter(0)
{
}

KdBuildQueue::~KdBuildQueue()
{
}

void KdBuildQueue::add(KdNode* n, Triangle** tl, const int nt, AABB* a, const int d)
{
	queue[tail].node = n;
	queue[tail].triangleList = tl;
	queue[tail].numTriangles = nt;
	queue[tail].aabb = a;
	queue[tail].depth = d;

	tail++;
	
	if (tail == KDBUILDQUEUESIZE)
		tail = 0;
	
	counter++;
}

QueueEntry& KdBuildQueue::remove(void)
{
	QueueEntry& answer = queue[head];
	head++;
	if (head == KDBUILDQUEUESIZE)
		head = 0;
	
	counter--;
	
	return answer;
}

void KdBuildQueue::print(void) const
{
	std::cout << "Printing Kd-queue:" << std::endl;
	std::cout << "Head: " << head << std::endl;
	std::cout << "Tail: " << tail << std::endl;
	for(int i = 0;i < KDBUILDQUEUESIZE;i++)
	{
		std::cout << "Number " << i << ": Node: " << queue[i].node << std::endl;
	}
	std::cout << std::endl;
}
